package com.shzu.jwc.ty.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.shzu.jwc.ty.common.Msg;
import com.shzu.jwc.ty.service.UserUpdatepassservice;

@RequestMapping("/usersys")
@Controller
public class UserSyscontroller {

	@Autowired
	UserUpdatepassservice userUpdatepassservice;
	
	@ResponseBody
	@RequestMapping(value="/updatepass.action",method=RequestMethod.POST)
	public Msg updatepass(@RequestParam("repassword")String repassword,@RequestParam("password")String password,HttpSession session) {
		try {
			String username=(String) session.getAttribute("username");
			if(userUpdatepassservice.isextis(username, repassword)==0)
				return Msg.error("原密码错误");
			userUpdatepassservice.updatepass(username, password);
			return Msg.success("操作成功");
		}catch(Exception ex) {
			return Msg.error("操作失败,"+ex.getMessage());
		}
	}
	
	@ResponseBody
	@RequestMapping(value="/jwc/updatepass.action",method=RequestMethod.POST)
	public Msg jwcupdatepass(@RequestParam("repassword")String repassword,@RequestParam("password")String password,HttpSession session) {
		try {
			String username=(String) session.getAttribute("username");
			if(userUpdatepassservice.isextis(username, repassword)==0)
				return Msg.error("原密码错误");
			userUpdatepassservice.updatepass(username, password);
			return Msg.success("操作成功");
		}catch(Exception ex) {
			return Msg.error("操作失败,"+ex.getMessage());
		}
	}
}
